<?php
namespace Framework\Library\Core;

/**
 * 配置项操作类
 */
class Config{
	
	public $DbHost = 'localhost';
	public $DbPort = '3306';
	public $DbUser = 'root';
	public $DbPswd = '123';
	public $DbName = '';
	
	public $DefaultModule = 'Default';
	public $DefaultAction = 'default';
	
	public $Timezone = 'Asia/Hong_Kong';
	
	private $appConfig;
	
	function __construct( $config_file ){
		$this ->appConfig = include $config_file;
		$this->initAppConfig();
	}
	
	/**
	 * 把应用配置更新到默认配置(如果有)
	 */
	private function initAppConfig(){
		foreach ($this as $k =>$v){
			if ( ($k != 'appConfig') && !empty($this ->appConfig[$k]) )
			$this->$k = $this ->appConfig[$k];
		}
	}
	
	public function __set ( $name, $value ){
		$this ->appConfig[$name] = $value;
	}
	
	public function __get ( $name ){
		if(!isset($this ->appConfig[$name])) return NULL;
		else return $this ->appConfig[$name];
	}
	
}